package org.chen.common.hotel.request;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;

import java.util.List;

import io.swagger.v3.oas.annotations.media.Schema;
import org.chen.common.hotel.dto.CustomAttractionDTO;

import javax.validation.Valid;
import javax.validation.constraints.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(description = "酒店搜索请求参数")
public class HotelSearchRequest {

    @Schema(description = "城市ID",
            example = "28",
            requiredMode = Schema.RequiredMode.REQUIRED)
    @Positive(message = "城市ID必须为正整数")
    private Integer cityId;

    @Schema(description = "国家ID",
            example = "1",
            requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @Positive(message = "国家ID必须为正整数")
    private Integer countryId;

    @Schema(description = "入住日期",
            example = "20241225",
            pattern = "yyyyMMdd",
            requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "入住日期不能为空")
    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "日期格式必须为 yyyy-MM-dd")
    private String checkInDate;

    @Schema(description = "退房日期",
            example = "20241228",
            pattern = "yyyyMMdd",
            requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "退房日期不能为空")
    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "日期格式必须为 yyyy-MM-dd")
    private String checkOutDate;

    @Schema(description = "房间数量",
            example = "1",
            minimum = "1",
            maximum = "10",
            defaultValue = "1")
    @Min(value = 1, message = "房间数量最少为1")
    @Max(value = 10, message = "房间数量最多为10")
    private Integer roomQuantity;

    @Schema(description = "成人数量",
            example = "1",
            minimum = "1",
            maximum = "20")
    @Min(value = 1, message = "成人数量最少为1")
    @Max(value = 20, message = "成人数量最多为20")
    private Integer adultCount;

    @Schema(description = "儿童数量",
            example = "1",
            minimum = "0",
            maximum = "10",
            defaultValue = "0")
    @Min(value = 0, message = "儿童数量不能为负数")
    @Max(value = 10, message = "儿童数量最多为10")
    private Integer childCount;

    @Schema(description = "儿童年龄列表(0-17岁)",
            example = "[5]",
            requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @Size(max = 10, message = "儿童年龄列表最多10个")
    private List<@Min(value = 0, message = "儿童年龄不能小于0")
    @Max(value = 17, message = "儿童年龄不能大于17") Integer> childAges;

    @Schema(description = "搜索关键词(酒店名称、地标等)",
            example = "",
            requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @Size(max = 100, message = "关键词长度不能超过100个字符")
    private String keyword;

    @Schema(description = "页码",
            example = "1",
            minimum = "1",
            defaultValue = "1")
    @Min(value = 1, message = "页码必须大于0")
    private Integer pageIndex = 1;

    @Schema(description = "每页条数",
            example = "10",
            minimum = "1",
            maximum = "20",
            defaultValue = "10")
    @Min(value = 1, message = "每页条数必须大于0")
    @Max(value = 20, message = "每页条数不能超过20")
    private Integer pageSize = 10;

    // 新增：排序方式
    @Schema(description = "排序方式",
            example = "9",
            allowableValues = {"5", "6", "9", "14"},
            requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @Pattern(regexp = "^(5|6|9|14)$", message = "排序方式只能是: 5(距离), 6(好评优先), 9(智能排序), 14(高星优先)")
    private String sortType = "9"; // 默认智能排序

    // 新增：选择的便捷景点ID（单选）
    @Schema(description = "选择的便捷景点ID",
            example = "1",
            requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    private Long convenientAttractionId;

    // 新增：自定义景点（单个）
    @Schema(description = "自定义景点，与便捷景点二选一",
            requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @Valid
    private CustomAttractionDTO customAttraction;

    @Valid
    @Schema(hidden = true)
    private Coordinate coordinate;

    @Data
    public static class Coordinate {
        private String scene;
        private Double latitude;
        private Double longitude;
    }
}